- [Instructor] Now that I'm in MATLAB,
I have a blank command window, and I can start
working with the commands and functions that I described.
I don't need to create a script.
I can just work here.
I'll start by defining a string variable,
so I'll call it str1, equals,
and then in single quotes, card, and Enter.
So there's my assignment.
Let's say I want to check to see if this
is a character string, so str1 is a character string.
I would use ischar, followed by left parentheses
and str1, the name of the variable.
Right parentheses, Enter, and I get a logical one,
so the value is true.
String one does in fact contain a character string.
I can also determine whether
individual characters are letters.
To do that, I would use isletter,
and then in parentheses, str1, and Enter.
And I get a logical array.
So I see that I have four elements
in the array, in the vector, and all of them have a one,
which means that they are all letters.
And if I look at C-A-R-D, that makes sense.
If I create a new string variable,
and I'll just call it str2, equals,
single quote, card51, and Enter.
There's my assignment.
If I do isletter, left parentheses,
str1, right parentheses, Enter.
Oh I'm sorry, I needed to check str2.
Isletter, left parentheses, str2, Enter, there we go.
I have six characters, the first of which are letters,
C-A-R-D, and the last two are not.
Isletter is very useful if you are expecting
a certain pattern, for example three letters,
followed by two numbers, followed by three letters again.
Then you can use isletter to make sure
that everything came in as expected.
As I mentioned before, numbers are stored
as double floating point numbers, so double length.
So if I were to create a new value,
I'll call it val1, equals 14, and Enter.
And I would ask is this value a real number?
So I'll type isreal, val1, Enter, and I see it is yes.
So even though it doesn't have a decimal component,
it could, so it is a real number,
meaning it's not a complex number,
such as one plus the square root of negative one,
which would be one plus i.
I can also check to determine the specific type
of a variable, or at least ask
if a variable is a specific type.
For that, I would use isa, followed by left parentheses,
and let's say if I want to ask if val1
is an eight-bit integer.
So I type in val1, and then a comma,
and then in single quotes because I am passing a string,
I would ask for an eight-bit integer, so it would be int8.
Close the quote, Enter, oh, I mistyped the variable name,
and MATLAB very helpfully changed
the variable name to val1 for me.
I'll press Enter, and I see in fact
it is not an eight-bit integer.
If I type isa, left parentheses val1,
getting it right this time, and then a comma,
and then in single quotes, the string double, and Enter.
Then I see that it is in fact
a double length floating point number.
It can be a pain to remember to check the values
that you're receiving, and a lot of steps
within your MATLAB scripts.
However, when you're just creating your scripts,
and you aren't quite sure how everything works,
these are valuable functions that you can use
to verify that you're at least receiving
the form of the variables that you want.